//静态内部类
class OuterClass{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    static class InnerCalss{
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;
        public void func(){
            System.out.println("staiv->InnerCalss::func()");
            OuterClass outerClass = new OuterClass();
            System.out.println(outerClass.data1);
            System.out.println(outerClass.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
    public void test(){
        InnerCalss innerCalss = new InnerCalss();
        System.out.println(data1);
        System.out.println(data2);
        System.out.println(data3);
        System.out.println(innerCalss.data4);
        System.out.println(innerCalss.data5);//外部类 可以访问静态内部类当中的所有成员
        System.out.println(innerCalss.data6);
    }
}
//非静态内部类
class OuterClass2{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    class InnerCalss2{
        public  int data1 = 11111;//结果为11111 就近原则
        public int data4 = 4;
        private int data5 = 5;
        //加一个final就可以定义静态成员，因为常量是在编译的时候就可以确定的
        public static final int data6 = 6;
        public void func(){
            System.out.println("InnerCalss::func()");
            //非静态内部类实例内部类比较麻烦，需要外部类的对象，而静态内部类不需要
            System.out.println(data1);
            System.out.println("======="+OuterClass2.this.data1);//内部类有两个this
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
    public void test(){
        InnerCalss2 innerCalss2 = new InnerCalss2();
        System.out.println(data1);
        System.out.println(data2);
        System.out.println(data3);
        System.out.println(innerCalss2.data4);
        System.out.println(innerCalss2.data5);
        System.out.println(InnerCalss2.data6);
    }
}
//局部内部类
class OuterClass3{

    public void func(){
        class InnerClass{
            public int a = 1;

            private  void test(){
                System.out.println("hello!");
            }
        }
        InnerClass innerClass = new InnerClass();
        innerClass.test();
    }
}

//匿名内部类
interface IA{
    void func();
}
class AA implements IA{
    @Override
    public void func() {
        System.out.println("hello!");
    }
}

public class Text {
    public static void main(String[] args) {
        new IA(){
            @Override
            public void func() {
                System.out.println("hello2");
            }
        }.func();

    }

    public static void main4(String[] args) {
        IA ia = new AA();
        ia.func();
    }

    public static void main3(String[] args) {
        OuterClass3 outerClass3 = new OuterClass3();
        outerClass3.func();
    }

    public static void main2(String[] args) {
        OuterClass2 outerClass2 = new OuterClass2();
        OuterClass2.InnerCalss2 innerCalss2 = outerClass2.new InnerCalss2();
        innerCalss2.func();
    }

    public static void main1(String[] args) {
        OuterClass.InnerCalss  innerCalss = new OuterClass.InnerCalss();
        innerCalss.func();
    }

}

